package com.xiaoyuer.yygh.cmn.controller;

import com.xiaoyuer.yygh.cmn.service.DictService;
import com.xiaoyuer.yygh.common.result.Result;
import com.xiaoyuer.yygh.model.entity.cmn.Dict;
import com.xiaoyuer.yygh.model.vo.DictDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin
public class DictController {

    @Autowired
    private DictService dictService;

    //根据数据id查询子数据列表
    @ApiOperation(value = "根据数据id查询子数据列表")
    @GetMapping("findChildData/{id}")
    public Result findChildData(@PathVariable Long id){
      List<Dict> dictList =dictService.findChlidData(id);
        return Result.ok(dictList);
    }


    //数据字典树状图
    @ApiOperation(value = "数据字典树状图")
    @GetMapping("/dictTree")
    public Result dictTree(){
        List<DictDataVo> dictList =dictService.dictTree();
        return Result.ok(dictList);
    }

    //数据字典导出（写）
    @ApiOperation(value = "数据字典导出")
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        dictService.exportData(response);
    }

    //数据字典导入（读）
    @ApiOperation(value = "数据字典导入")
    @PostMapping("/importData")
    public Result importData(MultipartFile file){
        dictService.importData(file);
        return Result.ok();
    }
}
